<?php

if (!hasPermission('section=admin')) {
	return new Ret(PERMISSION_DENIED. ': Missing right(s) for section admin');
}

// Das action array vorbereiten
$action = array();
$action['user']		= 'admin/user.php';
$action['rights']	= 'admin/rights.php';
$action['access']	= 'admin/access.php';
$action['news']		= 'admin/news.php';
$action['games']	= 'admin/games.php';

// Den Rückgabewert vorbereiten
$admin_ret = new Ret('admin/admin.tpl', 'admin/admin.css');

// Hier wird der Rückgabewert der subseite (Aktion) gespeichert
$admin_sub_ret = new Ret();

// Welche action soll geladen werden
if (isset($_GET['action'])) {
	
	if (!isset($action[$_GET['action']])) {
		
		$admin_sub_ret = new Ret(ERR_ACTION_DOES_NOT_EXIST. ': '. $_GET['action']);
		
		// warn
		$logger->logFile('The action '. $_GET['action'] .' does not exsist.', LEVEL_WARN);
		
	} else if (file_exists('includes/'. $action[$_GET['action']])) {
		
		// Die gewünschte action laden
		$admin_sub_ret = include 'includes/'. $action[$_GET['action']];
		
	} else {
		
		$admin_sub_ret = new Ret(INCLUDE_NOT_FOUND_EXCEPTION . ': includes/'.$action[$_GET['action']]);

		// error
		$logger->logFile("The include file '". 'includes/'.$action[$_GET['action']] ."' was not found.", LEVEL_ERROR);
	
	}
}

if (!$admin_sub_ret->get_template()) {
	
	if (file_exists('includes/'. $action['news'])) {
		
		$admin_sub_ret = include 'includes/'. $action['news'];
		
	} else {
		
		$admin_sub_ret = new Ret(INCLUDE_NOT_FOUND_EXCEPTION . ': includes/'.$action['news']);
		
		// error
		$logger->logFile("The include file '". 'includes/'.$action['news'] ."' was not found.", LEVEL_ERROR);
	
	}
}

// den subseiten return wert in das daten array schreiben
$admin_ret->add_data('action_ret', $admin_sub_ret);

return $admin_ret;

?>